package com.d3works.apps.hr.service.config;

import com.d3works.apps.account.db.Account;
import com.d3works.apps.account.db.AccountConfig;
import com.d3works.apps.account.db.Journal;
import com.d3works.apps.account.service.config.AccountConfigService;
import com.d3works.apps.hr.exception.HumanResourceExceptionMessage;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.i18n.I18n;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
public class AccountConfigHRService extends AccountConfigService {

  public Journal getExpenseJournal(AccountConfig accountConfig) throws D3worksException {
    if (accountConfig.getExpenseJournal() == null) {
      throw new D3worksException(
          accountConfig,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(HumanResourceExceptionMessage.EXPENSE_JOURNAL),
          accountConfig.getCompany().getName());
    }
    return accountConfig.getExpenseJournal();
  }

  public Account getExpenseEmployeeAccount(AccountConfig accountConfig) throws D3worksException {
    if (accountConfig.getEmployeeAccount() == null) {
      throw new D3worksException(
          accountConfig,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(HumanResourceExceptionMessage.EXPENSE_ACCOUNT),
          accountConfig.getCompany().getName());
    }
    return accountConfig.getEmployeeAccount();
  }

  public Account getExpenseTaxAccount(AccountConfig accountConfig) throws D3worksException {
    if (accountConfig.getExpenseTaxAccount() == null) {
      throw new D3worksException(
          accountConfig,
          TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
          I18n.get(HumanResourceExceptionMessage.EXPENSE_ACCOUNT_TAX),
          accountConfig.getCompany().getName());
    }
    return accountConfig.getExpenseTaxAccount();
  }
}
